#ifndef __VIDEOCAPTURE_H__
#define __VIDEOCAPTURE_H__

#include "video_capture.h"
#include "define.h"
#include "SDL.h"

#define MAX_DEVICENAME_LEN	256
#define MAX_DEVICEUNIQUEID_LEN	1024

typedef struct tagDeviceInfo
{
	char						szDeviceName[MAX_DEVICENAME_LEN];
	char						szUniqueName[MAX_DEVICEUNIQUEID_LEN];
	int							nIndex;
	vector<CaptureCapability>	vecCapability;
}DeviceInfo,*LPDeviceInfo;

class VideoCaptrueDataNotify
{
public:
	VideoCaptrueDataNotify(void){};
	virtual~VideoCaptrueDataNotify(void){};
public:
	virtual void OnCaptureData(int nId, const uint8_t * const pFrame[], int nWidth, int nHeight, uint64_t ulTimestamp)=0;
};

class CVideoCapture
{
public:
	CVideoCapture(VideoCaptrueDataNotify *pNotify);
	~CVideoCapture(void);

	void SetDisplayWindow(unsigned long ulPlayWnd);
	void SetDisplay(bool bIsDisplay);

	int InitVideoCapture(void);
	int UpdateVideoCaptureDevice(void);

	int GetDeviceList(vector<DeviceInfo> &vecDevice);

	int StartDevCapture(int nIndex, int nWidth, int nHeigth, int nFrameRate);
	int StartDevCaptureEx(const char *pUIDName, int nWidth, int nHeigth, int nFrameRate);

	int StopDevCapture(int nIndex);

	void OnVideoDataNotfiy(uint32_t id, uint32_t width, uint32_t height,
		const uint8_t* const slice[], uint64_t timestamp);

	void DisplaySetDialogBox(const char* pUIDName,
		const char* dialogTitle, void* parentWindow, uint32_t positionX, uint32_t positionY);

	void DisplaySetDialogBoxEx(int nIndex,
		const char* dialogTitle, void* parentWindow, uint32_t positionX, uint32_t positionY);

private:
	int GetDeviceCaps(const char *pDeviceUnique, vector<CaptureCapability> &vecCapability);
	int GetDeviceIndex(const char *pDeviceUnique);

	int Init();
	void UnInit(void);
	int DisplayVideo(const uint8_t* const slice[]);

private:
	VideoCaptrueDataNotify		*m_pNotify;
	int32_t						m_handle;

	int							m_nSrcWidth;
	int							m_nSrcHeight;

	int							m_nDspWidth;
	int							m_nDspHeight;

	vector<DeviceInfo>			m_vecDeviceInfo;
	unsigned long				m_ulPlayWnd;

	SDL_Surface					*m_pScreen;
	SDL_Overlay					*m_pBmp;

	bool						m_bDispaly;

	//FILE						*m_pOutFile;
};
#endif
